package deepbrain.simnetwork.mechanism;

import deepbrain.simnetwork.network.Network;
import deepbrain.simnetwork.network.NetworkState;
import deepbrain.simnetwork.network.NodeState;
import deepbrain.simnetwork.structure.Connection;

/**
 * A Probability And Operation without indeterminacy. The node will be firing if
 * all of the afferent nodes are firing.
 * 
 * @author Li Yang
 * @create 2009-2-25
 */
public class AndOperation extends GenericMechanism {

	public NodeState nextNodeState(int node, Network network, NetworkState state) {
		if (network.getAfferentConnections(node).size() == 0)
			return NodeState.MAXIMUM_ENTROPY;
		
		double firingProb = 1.0;
		for (Connection<?> connection : network.getAfferentConnections(node)) {
			firingProb *= state.getNodeState(connection.source)
					.getFiringProbability();
		}
		return NodeState.newNodeState(firingProb);
	}

	public String toString() {
		return "And Operation";
	}

}
